package com.aaa.ssm.service.impl;

import com.aaa.ssm.mapper.EmpMapper;
import com.aaa.ssm.mapper.PermissionMapper;
import com.aaa.ssm.pojo.dto.EmpDTO;
import com.aaa.ssm.pojo.dto.LoginDTO;
import com.aaa.ssm.pojo.dto.PermissionDTO;
import com.aaa.ssm.result.AjaxResult;
import com.aaa.ssm.service.EmpService;
import com.aaa.ssm.util.PermissionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.*;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private PermissionMapper permissionMapper;
    @Autowired
    private HttpSession session;


    @Override
    public EmpDTO login(String username,String password){
        //1.根据账号密码 查询员工eid
        LoginDTO admin = empMapper.selectEid(username, password);
        if(admin==null){
            throw new RuntimeException("对不起 账号或者密码错误");
        }
        Integer eid = admin.getEid();
        //2.根据eid查询员工信息
        EmpDTO  emp = empMapper.getEmpInfoByEid(eid);
        Integer state = emp.getState();
        if(state.equals(1)){
            throw new RuntimeException("账号被冻结");
        }else if(state.equals(2)){
            throw new RuntimeException("员工离职");
        }
        //3.黑名单 白名单 员工是否冻结
        return emp;


    }

    @Override
    public List<PermissionDTO> getPermission(Integer rid) {
        if(rid==1){
            return permissionMapper.getAllPermissions();
        }
        return  permissionMapper.getPermissionsByRid(rid);
    }
}
